const router = require('koa-router')()
const CountsHelp =require('../database/count/CountsHelp')


//统计聊天消息(每天)
router.get('/api/count/dateChatNum', async (ctx, next) => {

    let {date}=ctx.request.query

    let res= await CountsHelp.getCounts(date)

    let total_num=0
    let uid_list=[]

    if(res){
        total_num=res.total_num
        uid_list=res.uid_list
    }

    if(!date){
        date=CountsHelp.getTodayDate()
    }

    ctx.body={
        code:0,
        data:{
            date,
            total_msg_num:total_num,
            active_user_num:uid_list.length,
            active_user_list:uid_list
        }
    }
})


//统计聊天消息(每月)
router.get('/api/count/monthChatNum', async (ctx, next) => {
    let {month}=ctx.request.query
    let res= await CountsHelp.getMonthNums(month)

    ctx.body={
        code:0,
        data:{
            month,
            total_msg_num:res.msg_nums,
            active_user_num:res.user_lists.length,
            active_user_list:res.user_lists,

        }
    }
})



//统计一段时间内的走势
router.get('/api/count/chatNum', async (ctx, next) => {
    let {begin,end}=ctx.request.query
    let res= await CountsHelp.getNumsInSomeDay(begin,end)

    ctx.body={
        code:0,
        data:res
    }
})


router.post('/api/count/makfake',async (ctx, next) => {
    let {date,total_num}=ctx.request.body
    let res= await CountsHelp.addFakeMsg(date,total_num)

    ctx.body={
        code:0,
        data:res
    }
})


router.post('/api/count/removeCount',async (ctx, next) => {
    let {day}=ctx.request.body
    let res= await CountsHelp.removeCount(day)

    ctx.body={
        code:0,
        data:res
    }
})


router.post('/api/count/makeDateArr',async (ctx, next) => {
    let {begin,end}=ctx.request.body

    let res=await CountsHelp.makeDateArr(begin,end)

    ctx.body={
        code:0,
        data:res
    }

})







module.exports = router